#include <stdbool.h>
#include <stdio.h>
#define ElemType int
#define MAXSIZE 10
#define status int
// #define

typedef struct {
    ElemType data[MAXSIZE];
    int top;
} SqStack;

void initStack(SqStack *s) {
    s->top = -1;
}

//top指针指向-1为空栈
status stackEmpty(SqStack *s) {
    if (s->top == -1) {
        return true;
    } else {
        return false;
    }
}

//top指针等与MAZSIZE栈满，因为数组中数据下标范围是0-MAXSIZE-1
status stackOverFlow(SqStack *s) {
    if (s->top == MAXSIZE - 1) {
        return true;
    }
    return false;
}

status push(SqStack *s,ElemType data) {
    if (stackOverFlow(s)) {
        return false;
    }
    s->data[++s->top] = data;
    return true;
}

status pop(SqStack *s,ElemType *data) {
    if (stackEmpty(s)) {
        return false; //空栈
    }
    *data = s->data[s->top--];
    return true;
}

status getStackTopElem(SqStack *s,ElemType *data) {
    if (stackEmpty(s)) {
        return false;
    }
    *data = s->data[s->top];
    return true;
}

void testStack() {
    ElemType data;
    SqStack s;
    initStack(&s);
    printf("=================\n");
    printf("stackEmpty:%d\n", stackEmpty(&s));
    printf("stackOverFlow:%d\n", stackOverFlow(&s));
    push(&s, 10);
    printf("=================\n");
    printf("stackEmpty:%d\n", stackEmpty(&s));
    printf("stackOverFlow:%d\n", stackOverFlow(&s));
    getStackTopElem(&s, &data);
    printf("%d", data);
    pop(&s, &data);
}

int main() {
    testStack();
    // printf("%d", 2 + 4);
}
